#include <iostream>
#include <map>
//#include <string>  // 注意不是<string.h>（C风格字符串头文件）
using std::string;
using namespace std;
#include <iostream>
int lengthOfLongestSubstring(string s) {


    std::map<char, int> window;
    int start = 0, maxStart = 0, maxLength = 0;

    for (int i = 0; i < s.length(); ++i) {

        char current = s[i];

        // 检查当前字符是否已存在于窗口内
        if (window.find(current) != window.end() && window[current] >= start) {
            // 若存在，则调整窗口起始位置到重复字符的下一个位置
            start = window[current] + 1;
        }

        window[current] = i;


        int currentwindowlength = i - start + 1;

        if (currentwindowlength > maxLength) {
            maxLength = currentwindowlength;
            maxStart = start;
        }


    }

    return maxLength;


}


int main() {
    string s = "abcabcbb";

    int i =lengthOfLongestSubstring(s);
    cout << i << endl;

    return 0;
}
